package com.moji.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.moji.common.entity.MyPage;
import com.moji.common.utils.PageUtil;
import com.moji.entity.MjProductPurchase;
import com.moji.entity.MjProductPurchasePrice;
import com.moji.entity.dto.MjProductPurchasePriceDto;
import com.moji.entity.dto.QueryProductPurchasePriceDto;
import com.moji.entity.vo.PurchasePriceVo;
import com.moji.entity.vo.QueryVo;
import com.moji.mapper.MjProductPurchasePriceMapper;
import com.moji.service.MjProductPurchasePriceService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 产品选购价格表 服务实现类
 * </p>
 *
 * @author ccl
 * @since 2024-10-14
 */
@Service
public class MjProductPurchasePriceServiceImpl extends ServiceImpl<MjProductPurchasePriceMapper, MjProductPurchasePrice> implements MjProductPurchasePriceService {

    @Override
    public QueryVo queryByPage(QueryProductPurchasePriceDto dto) {
        QueryVo queryVo=new QueryVo();
        LambdaQueryWrapper<MjProductPurchasePrice> wrapper = new LambdaQueryWrapper<>();
        //标题
        wrapper.like(ObjectUtil.isNotEmpty(dto.getEndpointName()),MjProductPurchasePrice::getEndpointName
                ,dto.getEndpointName());
        wrapper.like(ObjectUtil.isNotEmpty(dto.getAccesstypeName()),MjProductPurchasePrice::getAccesstypeName
                ,dto.getAccesstypeName());
        wrapper.like(ObjectUtil.isNotEmpty(dto.getRegionName()),MjProductPurchasePrice::getRegionName
                ,dto.getRegionName());
        //创建时间倒叙
        wrapper.orderByDesc(MjProductPurchasePrice::getCreateTime);
        //PageHelper.startPage(dto.getPageNum(), dto.getPageSize());
        List<MjProductPurchasePrice> mjProductPurchases = list(wrapper);
        List<PurchasePriceVo> purchasePriceVos=new ArrayList<>();
        for(int i=0;i<14;i++){
            PurchasePriceVo purchasePriceVo=new PurchasePriceVo();
            if(i==0){
                purchasePriceVo.setTitle("区域code");
                purchasePriceVo.setDataIndex("regionCode");
                purchasePriceVos.add(purchasePriceVo);
            }
            if(i==1){
                purchasePriceVo.setTitle("区域名称");
                purchasePriceVo.setDataIndex("regionName");
                purchasePriceVos.add(purchasePriceVo);
            }
            if(i==2){
                purchasePriceVo.setTitle("数据API类型code");
                purchasePriceVo.setDataIndex("endpointCode");
                purchasePriceVos.add(purchasePriceVo);
            }
            if(i==3){
                purchasePriceVo.setTitle("数据API类型名称");
                purchasePriceVo.setDataIndex("endpointName");
                purchasePriceVos.add(purchasePriceVo);
            }
            if(i==4){
                purchasePriceVo.setTitle("调用方式code");
                purchasePriceVo.setDataIndex("accesstypeCode");
                purchasePriceVos.add(purchasePriceVo);
            }
            if(i==5){
                purchasePriceVo.setTitle("调用方式名称");
                purchasePriceVo.setDataIndex("accesstypeName");
                purchasePriceVos.add(purchasePriceVo);
            }
            if(i==6){
                purchasePriceVo.setTitle("5W/日调用量");
                purchasePriceVo.setDataIndex("d5wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("5W/日调用量");
                purchasePriceVo1.setDataIndex("d5Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==7){
                purchasePriceVo.setTitle("10W/日调用量");
                purchasePriceVo.setDataIndex("d10wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("10W/日调用量");
                purchasePriceVo1.setDataIndex("d10Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==8){
                purchasePriceVo.setTitle("50W/日调用量");
                purchasePriceVo.setDataIndex("d50wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("50W/日调用量");
                purchasePriceVo1.setDataIndex("d50Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==9){
                purchasePriceVo.setTitle("100W/日调用量");
                purchasePriceVo.setDataIndex("d100wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("100W/日调用量");
                purchasePriceVo1.setDataIndex("d100Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==10){
                purchasePriceVo.setTitle("150W/日调用量");
                purchasePriceVo.setDataIndex("d150wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("150W/日调用量");
                purchasePriceVo1.setDataIndex("d150Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==11){
                purchasePriceVo.setTitle("200W/日调用量");
                purchasePriceVo.setDataIndex("d200wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("200W/日调用量");
                purchasePriceVo1.setDataIndex("d200Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==12){
                purchasePriceVo.setTitle("500W/日调用量");
                purchasePriceVo.setDataIndex("d500wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("500W/日调用量");
                purchasePriceVo1.setDataIndex("d500Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
            if(i==13){
                purchasePriceVo.setTitle("1000W/日调用量");
                purchasePriceVo.setDataIndex("d1000wPrice");
                purchasePriceVo.setType("text");
                purchasePriceVos.add(purchasePriceVo);

                PurchasePriceVo purchasePriceVo1=new PurchasePriceVo();
                purchasePriceVo1.setTitle("1000W/日调用量");
                purchasePriceVo1.setDataIndex("d1000Status");
                purchasePriceVo1.setType("switch");
                purchasePriceVos.add(purchasePriceVo1);
            }
        }
        queryVo.setPurchasePriceVoList(purchasePriceVos);
        queryVo.setProductPurchasePriceList(mjProductPurchases);
        return queryVo;
    }

    @Override
    public boolean delete(Long id) {
        if(ObjectUtil.isEmpty(id)){
            throw new RuntimeException("主键ID不能为空,请核查!");
        }
        return this.removeById(id);
    }

    @Override
    public boolean add(MjProductPurchasePrice mjProductPurchasePrice) {
        mjProductPurchasePrice.setCreateTime(new Date());
        return this.save(mjProductPurchasePrice);
    }

    @Override
    public boolean edit(MjProductPurchasePrice mjProductPurchasePrice) {
        MjProductPurchasePrice mjProductPurchase1=this.getById(mjProductPurchasePrice.getId());
        BeanUtils.copyProperties(mjProductPurchasePrice,mjProductPurchase1);
        return this.updateById(mjProductPurchase1);
    }

    @Override
    public MjProductPurchasePrice detail(Long id) {
        if(ObjectUtil.isEmpty(id)){
            throw new RuntimeException("主键ID不能为空,请核查!");
        }
        return this.getById(id);
    }

    @Override
    public boolean editPriceStatus(MjProductPurchasePriceDto dto) {
        //调用梯度d5wPrice d10wPrice d50wPrice d100wPrice d150wPrice d200wPrice
        MjProductPurchasePrice mjProductPurchase1=this.getById(dto.getId());
        BeanUtils.copyProperties(dto,mjProductPurchase1);
        mjProductPurchase1.setD5Status(dto.isD5Status()+"");
        mjProductPurchase1.setD10Status(dto.isD10Status()+"");
        mjProductPurchase1.setD50Status(dto.isD50Status()+"");
        mjProductPurchase1.setD100Status(dto.isD100Status()+"");
        mjProductPurchase1.setD150Status(dto.isD150Status()+"");
        mjProductPurchase1.setD200Status(dto.isD200Status()+"");
        mjProductPurchase1.setD500Status(dto.isD500Status()+"");
        mjProductPurchase1.setD1000Status(dto.isD1000Status()+"");
        return this.updateById(mjProductPurchase1);
    }
}
